﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Visio = Microsoft.Office.Interop.Visio;
using System.Globalization;

namespace SPNetworkTopology
{
    class AlterVisioEnvironment
    {
        /// <summary>
        /// Alter the Visio Environment
        /// </summary>
        public AlterVisioEnvironment()
        {
            Visio.Window activeWindow = VisioObjects.visApplication.ActiveWindow;

            activeWindow.ShowGrid = 0;
            activeWindow.ShowGuides = 0;
            activeWindow.ShowConnectPoints = 0;
            activeWindow.ShowPageBreaks = 0;
            activeWindow.ShowRulers = 0;
            activeWindow.Windows.get_ItemFromID(Convert.ToInt16(Visio.VisWinTypes.visWinIDExternalData, CultureInfo.InvariantCulture)).Visible = true;

            foreach (Visio.Document doc in VisioObjects.visApplication.Documents)
            {
                foreach (Visio.Page currentPage in doc.Pages)
                {
                    if (currentPage.Shapes.Count.Equals(0))
                    {
                        currentPage.Delete(0);
                        continue;
                    }

                    currentPage.PageSheet.get_CellsSRC(
                           (short)Visio.VisSectionIndices.visSectionObject,
                           (short)Visio.VisRowIndices.visRowPageLayout,
                           (short)Visio.VisCellIndices.visPLOPlaceStyle).ResultIU = 1;
                    currentPage.PageSheet.get_CellsSRC(
                           (short)Visio.VisSectionIndices.visSectionObject,
                           (short)Visio.VisRowIndices.visRowPageLayout,
                           (short)Visio.VisCellIndices.visPLORouteStyle).ResultIU = 17;
                    currentPage.PageSheet.get_CellsSRC(
                           (short)Visio.VisSectionIndices.visSectionObject,
                           (short)Visio.VisRowIndices.visRowPageLayout,
                           (short)Visio.VisCellIndices.visPLOAvenueSizeX).ResultIU = 2;
                    currentPage.PageSheet.get_CellsSRC(
                           (short)Visio.VisSectionIndices.visSectionObject,
                           (short)Visio.VisRowIndices.visRowPageLayout,
                           (short)Visio.VisCellIndices.visPLOAvenueSizeX).ResultIU = 2;
                    currentPage.Layout();
                    currentPage.CenterDrawing();
                    currentPage.ResizeToFitContents();
                    currentPage.AutoSize = true;
                }
            }
        }
    }
}
